package com.erp.erp_mask.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.erp.erp_mask.mapper.TBomMapper;
import com.erp.erp_mask.pojo.TBom;
import com.erp.erp_mask.service.TBomService;
import com.erp.erp_mask.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @BelongsProject: erp
 * @BelongsPackage: com.erp.erp_mask.controller
 * @Author: wang
 * @CreateTime: 2024-05-18  00:36
 * @Description: TODO
 * @Version: 1.0
 * @effect:
 */
@RestController
@RequestMapping("/Tbom")
public class TBomController {
    @Resource
    private TBomService tBomService;
    @GetMapping("/index")
    public ModelAndView index(){
        return new ModelAndView("/pro/Bom");
    }
    @Resource
    public TBomMapper tBomMapper;
    @GetMapping("/searchlist")
    public Result searchlist(){
        return Result.success(tBomService.findById());
    }
    @PostMapping("/BomAdd")
    public Result BomAdd(@RequestBody TBom tBom){
        try{
            tBomService.faddlist(tBom);
            return Result.success("添加成功!");
        }catch (Exception e){
            return Result.fail("添加失败!");
        }
    }
    @GetMapping("/selectzhu")
    public Result selectzhu(Integer level){
        return Result.success(tBomService.selectflist(level));
    }
//    修改下拉框查询
    @GetMapping("/editsearch")
    public Result editsearch(){
        return Result.success(tBomService.list());
    }
    @PutMapping("/edit")
    public Result edit(@RequestBody TBom tBom){
        try{
            System.out.println(tBom);
            tBomMapper.edit(tBom);
           return Result.success("修改成功!");
        }catch (Exception e){
            return Result.fail("修改失败!");
        }
    }
    //删除判断
    @GetMapping("/delsearch")
    public Integer delsearch(Integer id){
        return tBomMapper.delsearch(id);
    }
    @DeleteMapping("/del")
    public Result del(Integer id){
        try{
            tBomMapper.deleteById(id);
            return Result.success("删除成功!");
        }catch (Exception e){
            return Result.fail("删除失败!");
        }
    }
}
